import { Module } from '@nestjs/common';
import { PrismaService } from './prisma/prisma.service';
import { ConfigModule } from '@nestjs/config'; // 导入配置模块
import { PlanModule } from './plan/plan.module';
import { PrismaModule } from './prisma/prisma.module'; 
import { UsersModule } from './users/users.module';
import { ScheduleModule } from '@nestjs/schedule';
import { TasksService } from './tasks/tasks.service';
import { MailerModule } from '@nestjs-modules/mailer';
import { join } from 'path';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { APP_GUARD } from '@nestjs/core';
import { JwtAuthGuard } from './auth/jwt-auth.guard';
import { AuthModule } from './auth/auth.module';

@Module({
  imports: [
    ScheduleModule.forRoot(),
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    PlanModule,
    PrismaModule,
    UsersModule,
    MailerModule.forRoot({
      transport: {
        host: 'smtp.126.com',  // 126邮箱的SMTP服务器
        port: 465,
        secure: true,
        auth: {
          user: 'samlovegod@126.com',  // 你的126邮箱
          pass: 'Xu137200',     // 你的SMTP授权码
        },
      },
      template: {
        dir: join(__dirname, '..', 'templates'),
        adapter: new HandlebarsAdapter(),
        options: {
          strict: true,
        },
      },
      defaults: {
        from: '"提醒" <samlovegod@126.com>',  // 发件人信息
      },
    }),
    AuthModule,
  ],
  controllers: [],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    TasksService,
  ],
})
export class AppModule {}
